/**
******************************************************************************************
* @file LCDProjector.h
* @brief Management of the LCD and dualButton bricklets. Management of all user interface.
* @date 14 avril 2015
* @author Benjamin Lancinot
*****************************************************************************************/
/* COPYRIGHT ****************************************************************************
*****************************************************************************************
* Copyright (c) 2015, Audrey LOISEAU and Benjamin LANCINOT.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
*    list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
*    this list of conditions and the following disclaimer in the documentation
*    and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************************************/

#ifndef LCD_H
#define LCD_H

/*******************************************************************************************
* INCLUSION
********************************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <stdbool.h>
#include <string.h>
#include <time.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/wait.h>
#include <sys/errno.h>

#include "type_protected.h"
#include "observer.h"
#include "MercureLover.h"
#include "HumidityTester.h"
#include "ConnectionState.h"
#include "ip_connection.h"
#include "bricklet_lcd_20x4.h"
#include "bricklet_dual_button.h"

/*******************************************************************************************
* DEFINES
********************************************************************************************/

#define TRUE 1
#define FALSE 0

/*******************************************************************************************
* TYPES
********************************************************************************************/

/**
 * @struct LCDProjector
 */
typedef struct LCDProjector{
	int carryOn;
	pthread_t lcdThread;
        LCD20x4 lcdSensor;
        DualButton dualButtonSensor;
        int isDisplaying;
        int displayMode;
	int BAL_id;
	Observer* observer;

        int * nannyIsAlive;

	void (*start)(struct LCDProjector*, int *);
	void (*stop)(struct LCDProjector*);
	void (*destroy)(struct LCDProjector**);

}LCDProjector;

/**
 * @enum LCDDisplayValue
 */
typedef enum LCDDisplayValue_t{
	TEMPERATURE=0,
        HUMIDITY=1,
        CRITICALITY_TEMPERATURE=2,
        CRITICALITY_HUMIDITY=3,
        CONNECTION_STATUS=4,
	AVERAGE_TEMPERATURE=5,
        AVERAGE_HUMIDITY=6,
        NV=-1 //no value
}LCDDisplayValue;


/**
 * @enum LCDDisplayState
 */
typedef enum LCDDisplayState_t{
	ECRAN_GENERAL=0,
	ECRAN_TEMPERATURE=1,
        ECRAN_HUMIDITY=2,
	CHANGE_DATA=3,
        ECRAN_KILLDISPLAY=4,
        ECRAN_KILLNANNY=5,
        ECRAN_CANCEL=6
}LCDDisplayState;

/**
 * @struct LCDMessage
 */
typedef struct LCDMessage{
	LCDDisplayValue action;
	char valeur[10];
	int carryOn;
} LCDMessage;



/**
 * @struct MQ_msg
 */
typedef struct MQ_msg {
	long mtype;
	LCDMessage message;
} MQ_msg;

/*******************************************************************************************
* FUNCTIONS
********************************************************************************************/

/**
 * @brief Constructor
 * @param ipcon Ipconnection for link bricklet to the rest of bricks/bricklets
 * @return Pointer to a new LCDProjector
 **/
LCDProjector* LCDProjector_create(IPConnection);

#endif
